import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Guardian here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Guardian extends Cangrejo
{
    
    
    /**
     * Act - do whatever the Guardian wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Guardian(){
        
       
        
    }
        
    public void act() 
    {
        Actor a;
        java.util.List c;
        c=getObjectsInRange(500, Cartman.class) ;
        World w=getWorld();
        Cartman ca=((Mundo)getWorld()).getCartman();
        if(!c.isEmpty()){
            /*if(ca.getDir()==1)
               setLocation(getX()-1,getY());
            if(ca.getDir()==2)
               setLocation(getX()+1,getY());*/
            turnTowards(ca.getX(),ca.getY());
            
            move(1);
            
        }
        
        
         if(isTouching(Bala.class)){
         a=getOneIntersectingObject(Bala.class);
         w.removeObject(a);
         salud-=(((Bala)a).getDanio())/2;
        }
        
        if(salud<=0)
         w.removeObject(this);
    }    
}
